package com.huibei.wateradmin.common.message;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * PC端分页请求基础类
 * Created by wanglinlin on 2016/8/23.
 */
public class ReqAdminListMsg {
    private Integer start = 0;
    private Integer length = 20;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date fromDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date toDate;

    public Integer getStart() {
        return start;
    }

    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getLength() {
        return length;
    }

    public void setLength(Integer length) {
        this.length = length;
    }

    public Date getFromDate() {
        return fromDate;
    }

    public void setFromDate(Date fromDate) {
        this.fromDate = fromDate;
    }

    public Date getToDate() {
        return toDate;
    }

    public void setToDate(Date toDate) {
        this.toDate = toDate;
    }

    private Integer getPageNum() {
        return start / length;
    }

    public PageRequest getPageRequest() {
        return new PageRequest(getPageNum(), length , Sort.Direction.DESC,"id");
    }

    @Override
    public String toString() {
        return "ReqAdminListMsg{" +
                "start=" + start +
                ", length=" + length +
                ", fromDate=" + fromDate +
                ", toDate=" + toDate +
                '}';
    }
}
